package onework;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.*;
import java.util.Random;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class Manage {
    public static Map<String, Lesson> lessonICO=new HashMap<>();
    public static Map<String, Group> groupICO=new HashMap<>();
    public static Map<String, Student> studentICO=new HashMap<>();
    //获取菜单
    public static String getMenu(){
        Scanner scanner=new Scanner(System.in);
        System.out.println("-----------------教学管理系统---------------");
        System.out.println("-----------------1，班级管理---------------");
        System.out.println("-----------------2，小组管理---------------");
        System.out.println("-----------------3，学生管理---------------");
        System.out.println("-----------------4，随机点名---------------");
        System.out.println("-----------------教学管理系统---------------");
        System.out.print("请选择菜单:");
        String select=scanner.next();
        System.out.println("我输入了:"+select);
        return select;
    }
    public static boolean manageLesson(){
        Scanner scanner=new Scanner(System.in);
        System.out.println("-------------------班级管理---------------");
        System.out.println("-----------------1，新增班级---------------");
        System.out.println("-----------------2，维护班级---------------");
        System.out.println("-----------------3，班级列表---------------");
        System.out.println("-------------------班级管理---------------");
        String select=scanner.next();
        //继续实现1,2,3三个功能
        if("1".equals(select)){
            HashMap<String,Lesson> lessonICO=new HashMap<>();
            System.out.println("请输入班级名:");
            String classname=scanner.next();
            //创建班级实例
            Lesson lesson=new Lesson();
            lesson.classname=classname;
            //用学号判断学生是否已经存在
            Manage.lessonICO.put(lesson.classname, lesson);
            System.out.println("班级 " + lesson.classname + " 已创建并存入管理器中。");
            return true;
        }
        if("2".equals(select)){
            System.out.println("-----------------1，修改班级---------------");
            System.out.println("-----------------2，删除班级---------------");
            System.out.println("---请输入你的选择---");
            String select2=scanner.next();
            if("1".equals(select2)){
                System.out.print("输入班级: ");
                String classname=scanner.next();
                Lesson lesson= Manage.lessonICO.get(classname);
                //修改学生信息
                System.out.println("修改班级：");
                String classnames= scanner.next();
                //真正修改
                lesson.classname=classnames;
                Manage.lessonICO.put(lesson.classname,lesson);
                return true;
            }
            if("2".equals(select2)){
                System.out.print("输入班级: ");
                String classname=scanner.next();
                //判断是否存在，不存在怎么办
                Manage.lessonICO.remove(classname);
                return true;
            }
        }
        if("3".equals(select)){
            //打印班级列表
            System.out.println("--------班级列表--------");
            for (String className : Manage.lessonICO.keySet()) {
                System.out.println("班级名: " + className);
            }
            if (Manage.lessonICO.isEmpty()) {
                System.out.println("目前没有任何班级。");
            }
            return true;
        }
        return true;
    }
    public static boolean manageGroup(){
        Scanner scanner=new Scanner(System.in);
        System.out.println("-------------------小组管理---------------");
        System.out.println("-----------------1，新增小组---------------");
        System.out.println("-----------------2，维护小组---------------");
        System.out.println("-----------------3，小组列表---------------");
        System.out.println("-------------------小组管理---------------");
        String select=scanner.next();
        //继续实现1,2,3三个功能
        if("1".equals(select)){
            HashMap<String,Group> groupICO=new HashMap<>();
            System.out.println("请输入小组序号:");
            String number=scanner.next();
            System.out.println("请输入小组成员1:");
            String member1=scanner.next();
            System.out.println("请输入小组成员2:");
            String member2=scanner.next();
            System.out.println("请输入小组分数:");
            String score=scanner.next();
            //创建小组实例
            Group group=new Group();
            group.number=number;
            group.member1=member1;
            group.member2=member2;
            group.score=score;
            //用学号判断学生是否已经存在
            Manage.groupICO.put(group.number, group);
            System.out.println("小组 " + group.number + " 已创建并存入管理器中。");
            return true;
        }
        if("2".equals(select)){
            System.out.println("-----------------1，修改小组---------------");
            System.out.println("-----------------2，删除小组---------------");
            System.out.println("---请输入你的选择---");
            String select2=scanner.next();
            if("1".equals(select2)){
                System.out.print("输入小组序号: ");
                String number=scanner.next();
                Group group= Manage.groupICO.get(number);
                //修改学生信息
                System.out.println("修改小组：");
                String numbers= scanner.next();
                group.number=numbers;
                String member1= scanner.next();
                group.member1=member1;
                String member2= scanner.next();
                group.member2=member2;
                String score= scanner.next();
                group.score=score;
                Manage.groupICO.put(group.number,group);
                return true;
            }
            if("2".equals(select2)){
                System.out.print("输入小组序号: ");
                String number=scanner.next();
                //判断是否存在，不存在怎么办
                Manage.groupICO.remove(number);
                return true;
            }
        }
        if("3".equals(select)){
            //打印小组列表
            System.out.println("当前小组列表：");
            if (Manage.groupICO.isEmpty()) {
                System.out.println("没有任何小组。");
            } else {
                for (Map.Entry<String, Group> entry : Manage.groupICO.entrySet()) {
                    Group group = entry.getValue();
                    System.out.println("小组序号: " + group.number +
                            ", 成员1: " + group.member1 +
                            ", 成员2: " + group.member2 +
                            ", 分数: " + group.score);
                }
            }
            return true;
        }
        return true;
    }
    public static boolean manageStudent(){
        Scanner scanner=new Scanner(System.in);
        System.out.println("-------------------学生管理---------------");
        System.out.println("-----------------1，新增学生---------------");
        System.out.println("-----------------2，维护学生---------------");
        System.out.println("-----------------3，学生列表---------------");
        System.out.println("-------------------学生管理---------------");
        String select=scanner.next();
        //继续实现1,2,3三个功能
        if("1".equals(select)){
            HashMap<String, Student> studentICO=new HashMap<>();
            System.out.println("请输入学生学号:");
            String number=scanner.next();
            System.out.println("请输入学生姓名:");
            String name=scanner.next();
            System.out.println("请输入学生班级:");
            String grade=scanner.next();
            System.out.println("请输入学生小组:");
            String team=scanner.next();
            System.out.println("请输入学生考勤:");
            String attendance=scanner.next();
            System.out.println("请输入学生答题情况:");
            String reply=scanner.next();
            System.out.println("请输入学生分数:");
            String grades=scanner.next();
            //创建小组实例
            Student student=new Student();
            student.number=number;
            student.name=name;
            student.grade=grade;
            student.team=team;
            student.attendance=attendance;
            student.reply=reply;
            student.grades=grades;
            //用学号判断学生是否已经存在
            Manage.studentICO.put(student.name, student);
            System.out.println("学生 " + student.name + " 已创建并存入管理器中。");
            return true;
        }
        if("2".equals(select)){
            System.out.println("-----------------1，修改学生---------------");
            System.out.println("-----------------2，删除学生---------------");
            System.out.println("---请输入你的选择---");
            String select2=scanner.next();
            if("1".equals(select2)){
                System.out.print("输入学生姓名: ");
                String name=scanner.next();
                Student student= Manage.studentICO.get(name);
                //修改学生信息
                System.out.println("修改学生：");
                String numbers= scanner.next();
                student.number=numbers;
                String names= scanner.next();
                student.name=names;
                String grade= scanner.next();
                student.grade=grade;
                String team= scanner.next();
                student.team=team;
                String attendance= scanner.next();
                student.attendance=attendance;
                String reply= scanner.next();
                student.reply=reply;
                String grades= scanner.next();
                student.grades=grades;
                Manage.studentICO.put(student.name,student);
                return true;
            }
            if("2".equals(select2)){
                System.out.print("输入学生姓名: ");
                String name=scanner.next();
                //判断是否存在，不存在怎么办
                Manage.studentICO.remove(name);
                return true;
            }
        }
        if("3".equals(select)){
            //打印学生列表
            System.out.println("---------------学生列表---------------");
            if (Manage.studentICO.isEmpty()) {
                System.out.println("当前没有学生信息。");
            } else {
                for (Student student : Manage.studentICO.values()) {
                    System.out.println("学号: " + student.number +
                            ", 姓名: " + student.name +
                            ", 班级: " + student.grade +
                            ", 小组: " + student.team +
                            ", 考勤: " + student.attendance +
                            ", 答题情况: " + student.reply +
                            ", 分数: " + student.grades);
                }
            }
            System.out.println("-------------------------------------");
            return true;
        }
        return true;
    }
    public static boolean random(){
        Scanner scanner=new Scanner(System.in);
        System.out.println("-------------------随机点名---------------");
        System.out.println("-----------------1，随机抽组并给小组评分------");
        System.out.println("-----------------2，在小组中随机抽取学生-----");//记录考勤答题情况
        System.out.println("-----------------3，在班级中随机抽取学生-----");//记录考勤答题情况
        System.out.println("-----------------4，导出学生成绩------------");
        String select=scanner.next();
        //实现1到7的功能
        if("1".equals(select)){
            if (groupICO.isEmpty()) {
                System.out.println("没有可用的组！");
                return false;
            }
            List<String> groupKeys = new ArrayList<>(groupICO.keySet());
            String randomGroup = groupKeys.get(new Random().nextInt(groupKeys.size()));
            System.out.println("随机抽取的组是: " + randomGroup);
            Group group= Manage.groupICO.get(randomGroup);
            System.out.println("小组序号: " + group.number +
                    ", 成员1: " + group.member1 +
                    ", 成员2: " + group.member2 +
                    ", 分数: " + group.score);
            System.out.println("请给小组评分");
            String score = scanner.next();
            group.score=score;
            return true;
        }
        if("2".equals(select)){
            System.out.print("请输入小组序号: ");
            String number = scanner.next();
            Group group = groupICO.get(number);
            if (group == null ) {
                System.out.println("该组不存在或没有学生！");
                return false;
            }
            else{
                List<String> members = new ArrayList<>(Arrays.asList(group.member1, group.member2));
                Random random = new Random();
                int randomIndex = random.nextInt(members.size()); // 生成随机索引
                String randomStudentId = members.get(randomIndex); // 随机获取学生的编号
                Student student = Manage.studentICO.get(randomStudentId);
                System.out.println("学号: " + student.number +
                        ", 姓名: " + student.name +
                        ", 班级: " + student.grade +
                        ", 小组: " + student.team +
                        ", 考勤: " + student.attendance +
                        ", 答题情况: " + student.reply +
                        ", 分数: " + student.grades);
                System.out.println("给学生记录考勤");
                student.attendance=student.attendance+"1";
                System.out.println("记录学生答题情况");
                String reply=scanner.next();
                student.reply=reply;
                return true;
            }
        }
        if("3".equals(select)){
            //在班级中随机抽取学生
            while(true){
                System.out.print("请输入班级: ");
                String lesson = scanner.next();
                List<String> studentKeys = new ArrayList<>(studentICO.keySet());
                String randomStudent = studentKeys.get(new Random().nextInt(studentKeys.size()));
                Student student= Manage.studentICO.get(randomStudent);
                if(student.grade.equals(lesson)){
                    System.out.println("随机抽取的学生是是: " +"学号: " + student.number +
                            ", 姓名: " + student.name +
                            ", 班级: " + student.grade +
                            ", 小组: " + student.team +
                            ", 考勤: " + student.attendance +
                            ", 答题情况: " + student.reply +
                            ", 分数: " + student.grades);
                    System.out.println("给学生记录考勤");
                    student.attendance=student.attendance+"1";
                    System.out.println("记录学生答题情况");
                    String reply=scanner.next();
                    student.reply=reply;
                    break;
                }
            }
            return true;
        }
        if("4".equals(select)){
            System.out.println("--------学生成绩表--------");
            if (Manage.studentICO.isEmpty()) {
                System.out.println("当前没有学生信息。");
            }
            else {
                for (Student student : Manage.studentICO.values()) {
                    System.out.println("学号: " + student.number +
                            ", 姓名: " + student.name +
                            ", 班级: " + student.grade +
                            ", 小组: " + student.team +
                            ", 分数: " + student.grades);
                }
            }
            System.out.println("-------------------------------------");
            return true;
        }
        return true;
    }
}